home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / FORMAT.C < prev    next >
C/C++ Source or Header  |  1993-04-28  |  2KB  |  81 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 04-25-93 (19:57)             Number: 27
  4. From: BOB STOUT                    Refer#: 23
  5.   To: GENE SENYSZYN                 Recvd: NO  
  6. Subj: formatting a floppy            Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. In a message of <Apr 22 03:40>, Gene Senyszyn (1:2606/213@fidonet) writes:
  9.  
  10.  >How does one go about formatting a floppy(not meaning shelling and running
  11.  >format) in C? If possible, post a small example about how to go about doing
  12.  >it, as I seem to be stuck.
  13.  
  14.   From SNIPPETS, here's a heavy-handed approach which calls FORMAT, but does it
  15. transparently. The advantage, of course, is that it makes the executable very sm
  16. all.
  17.  
  18. /*
  19. **  FORMAT.C - Use DOS FORMAT to format a diskette
  20. **
  21. **  Original Copyright 1992 by Bob Stout as part of
  22. **  the MicroFirm Function Library (MFL)
  23. **
  24. **  This subset version is hereby donated to the public domain.
  25. */
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. enum {ERROR = -1, SUCCESS};
  31.  
  32. /*
  33. **  format
  34. **
  35. **  Formats a specified floppy disk with optional switches.
  36. **
  37. **  Parameters: 1 - Drive letter ('A', 'B', ...) to format
  38. **              2 - Formatting switches in FORMAT.COM format, e.g. "/4"
  39. **              3 - Volume label
  40. **
  41. **  Returns: SUCCESS or ERROR
  42. */
  43.  
  44. int format(char drive, char *switches, char *vlabel)
  45. {
  46.       char command[128], fname[13];
  47.       FILE *tmpfile;
  48.  
  49.       tmpnam(fname);
  50.       if (NULL == (tmpfile = fopen(fname, "w")))
  51.             return ERROR;                       /* Can't open temp file */
  52.       fprintf(tmpfile, "\n%s\nN\n", vlabel);
  53.       fclose(tmpfile);
  54.  
  55.       sprintf(command, "format %c: /V %s < %s > NUL", drive, switches, fname);
  56.  
  57.       system(command);
  58.  
  59.       remove(fname);
  60.  
  61.       return SUCCESS;
  62. }
  63.  
  64. #ifdef TEST
  65.  
  66. void main(void)
  67. {
  68.       int retval = format((char)'a', "/4", "dummy_test");
  69.  
  70.       printf("format() returned %d\n", retval);
  71. }
  72.  
  73. #endif
  74.  
  75.  
  76. --- QM v1.00
  77.  * Origin: MicroFirm : Down to the C in chips (1:106/2000.6)
  78. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  79. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 280/1
  80. SEEN-BY: 390/1 396/1 5 15 2270/1 2440/5 3603/20
  81.